//
//  ADViewController.m
//  IOS 引导条——索引
//
//  Created by Adiljan on 2016/12/17.
//  Copyright © 2016年 Adiljan. All rights reserved.
//

#import "ADViewController.h"
#import "LGUIView.h"
#import "ADCell.h"



#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT [UIScreen mainScreen].bounds.size.height

@interface ADViewController ()<UITableViewDelegate,UITableViewDataSource>{
    LGUIView *lgView;
    

}
@property (weak, nonatomic) IBOutlet UITableView *tblAD;

@end

@implementation ADViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initView];
    [self creatTableView];
    [self creatLGView];
}

-(void)initView{
    [self.tblAD registerNib:[UINib nibWithNibName:@"ADCell" bundle:nil] forCellReuseIdentifier:@"ADCell"];
  
}
-(void)creatTableView
{
    self.tblAD.delegate = self;
    self.tblAD.dataSource = self;
    self.tblAD.showsVerticalScrollIndicator = NO;
    self.tblAD.showsHorizontalScrollIndicator = NO;
    
    
}

-(void)creatLGView
{
    NSMutableArray * arr = [NSMutableArray new];
    for (int i = 0; i < 26; i ++)
    {
        unichar ch = 65 + i;
        NSString * str = [NSString stringWithUTF8String:(char *)&ch];
        [arr addObject:str];
    }
    
    lgView = [[LGUIView alloc]initWithFrame:CGRectMake(0, 100, 40, HEIGHT - 140) indexArray:arr directionType:isLeft];
    [self.view addSubview:lgView];
    
    [lgView selectIndexBlock:^(NSInteger section)
     {
         [self.tblAD selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:section]
                                 animated:NO
                           scrollPosition:UITableViewScrollPositionTop];
     }];
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
    lbl.backgroundColor = [UIColor grayColor];
    unichar ch = 65 + section;
    NSString * str = [NSString stringWithUTF8String:(char *)&ch];
    lbl.text = str;
    lbl.textAlignment = NSTextAlignmentRight;
    return lbl;
}
//-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
//{
//    unichar ch = 65 + section;
//    NSString * str = [NSString stringWithUTF8String:(char *)&ch];
//    return str;
//}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 30;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 26;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ADCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ADCell"];
    
    cell.label.text = [NSString stringWithFormat:@"%ld",indexPath.row];
    cell.label.textColor = [UIColor colorWithRed:35/255.0 green:94/255.0 blue:44/255.0 alpha:1.0];
    
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
